﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using KeywordDistributeInterface;

namespace KeywordDistributeService
{   

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
    ConcurrencyMode = ConcurrencyMode.Single)]
    public class ServiceImpl : IKeywordDistribute
    {

        #region IKeywordDistribute Members

        public string GetKeywork(int type)
        {
            string keywordName = null;
            using (CaijiDataContext db = CaijiDataContext.GetDataContext())
            {
                var hitRecord = db.HitRecords.First();

                int clickedKeywordID = 0;
                switch (type)
                {
                    case 1:
                        clickedKeywordID = hitRecord.ClickKeywordID;
                        break;
                    case 2:
                        clickedKeywordID = hitRecord.KeywordID.Value;
                        break;
                    case 3:
                        clickedKeywordID = hitRecord.FaxID;
                        break;

                }

                var keyword = db.ExecuteQuery<Keyword>("select top 1 * from tbKeyword where ID>" + clickedKeywordID + " order by ID ").First();

                switch (type)
                {
                    case 1:
                        hitRecord.ClickKeywordID = keyword.ID;
                        keywordName = keyword.StringKeyword;
                        break;
                    case 2:
                        hitRecord.KeywordID = keyword.ID;
                        keywordName = keyword.StringKeyword;
                        break;
                    case 3:
                        hitRecord.FaxID = keyword.ID;
                        keywordName = "无锡" + keyword.StringKeyword;
                        break;

                }
                db.SubmitChanges();
            }

             return keywordName;
        }

        #endregion
    }
}
